package shiqi.db;

import shiqi.constants.DbConstants;
import shiqi.constants.DbEnum;
import shiqi.db.user.MapUserDb;
import shiqi.db.user.UserDb;
import shiqi.model.User;


/**
 * @program: ascend
 * @description: 数据库工厂类，用于生成表数据
 * @author: shiqi
 * @create: 2022-03-17 16:22
 **/
public class DbFactory {

    private static final Db<User, Long> userDb = new UserDb();
    private static final Db<User, Long> mapUserDb = new MapUserDb();
    static {
        userDb.initData();
        mapUserDb.initData();
    }

    /**
     * @author shiqi
     * @createTime 2022/3/17 16:28
     * @desc 根据标识找到对应数据库
     * @param
     * @return shiqi.db.Db
     */
    public static Db getReallyDb(String dbConstant) {
        switch (dbConstant) {
            case DbConstants.USERDATASOURCE:
                return userDb;
            case DbConstants.MAPUSERDATASOURCE:
                return mapUserDb;
            default:
                return null;
        }
    }

    public static Db getReallyDb(DbEnum dbEnum) {
        switch (dbEnum) {
            case USERDATASOURCE:
                DbEnum.printFeatureInfo(dbEnum.getName());
                return userDb;
            case MAPUSERDATASOURCE:
                DbEnum.printFeatureInfo(dbEnum.getName());
                return mapUserDb;
            default:
                return null;
        }
    }
}
